package com.water.app.Config;

import com.water.app.JwtUtil;
import jakarta.websocket.HandshakeResponse;
import jakarta.websocket.server.HandshakeRequest;
import jakarta.websocket.server.ServerEndpointConfig;
import org.springframework.context.ApplicationContext;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
public class GetHttpSessionConfig extends ServerEndpointConfig.Configurator{
    private ApplicationContext applicationContext;

    @Override
    public void modifyHandshake(ServerEndpointConfig sec, HandshakeRequest request, HandshakeResponse response) {
        List<String> list = request.getHeaders().get("Authorization");
        String token = list.get(0);
        int userId = JwtUtil.parseJwt(token);
        sec.getUserProperties().put("userId", userId);
    }

}
